package com.qianzhou.eduCourseBoot.controller;

import com.qianzhou.eduCommon.constant.Constants;
import com.qianzhou.eduCommon.dto.CourseLessonDTO;
import com.qianzhou.eduCommon.dto.CourseSectionDTO;
import com.qianzhou.eduCommon.vo.CourseLessonVO;
import com.qianzhou.eduCommon.vo.CourseSectionVO;
import com.qianzhou.eduCommon.vo.CourseVO;
import com.qianzhou.eduCommon.vo.ResultVO;
import com.qianzhou.eduCourseBoot.service.CourseContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/courseContent")
public class CourseContentController {
    @Autowired
    private CourseContentService courseContentService;

    /**
     * @Author: qian.zhou
     * @Description: 根据课程id查找对应的课程的章节和课时的信息
     * @DateTime: 2021/10/12 10:39
     * @Params: * @Param courseId:
     * @Return: * @return: com.qianzhou.eduCommon.vo.ResultVO
     */
    @RequestMapping("/findSectionAndLesson/{courseId}")
    public ResultVO findSectionAndLesson(@PathVariable Integer courseId) {
        if (courseId == null) {
            return ResultVO.fail(Constants.FAILURE_PARAMS, Constants.FAILURE_TRANSFER_PARAMS, null);
        }
        List<CourseSectionVO> courseSectionVOS = courseContentService.findSectionAndLesson(courseId);
        return ResultVO.ok(Constants.SUCCESS_STATUS, Constants.SUCCESS, courseSectionVOS);
    }

    /**
     * @Author: qian.zhou
     * @Description: 更新章节状态信息
     * @DateTime: 2021/10/12 16:26
     * @Params: * @Param dto:
     * @Return: * @return: com.qianzhou.eduCommon.vo.ResultVO
     */
    @RequestMapping("/updateSectionStatus")
    public ResultVO updateSectionStatus(@RequestBody CourseSectionDTO dto) {
        if (dto.getCourseId() == null) {
            return ResultVO.fail(Constants.FAILURE_PARAMS, Constants.FAILURE_TRANSFER_PARAMS, null);
        }
        Integer num = courseContentService.updateSectionStatus(dto);
        if (num == 1) {
            return ResultVO.ok(Constants.SUCCESS_STATUS, Constants.UPDATE_STATUS_SUCCESS, null);
        }
        return ResultVO.fail(Constants.FAILURE_STATUS, Constants.UPDATE_STATUS_FAILURE, null);
    }

    /**
     * @Author: qian.zhou
     * @Description: 根据id查询对应的课程的信息，获取到对应的id和name的值
     * @DateTime: 2021/10/12 16:37
     * @Params: * @Param null:
     * @Return: * @return: null
     */
    @RequestMapping("/findCourseByCourseId/{courseId}")
    public ResultVO findCourseById(@PathVariable Integer courseId) {
        CourseVO courseVO = courseContentService.findCourseById(courseId);
        return ResultVO.ok(Constants.SUCCESS_STATUS, Constants.SUCCESS, courseVO);
    }

    /**
     * @Author: qian.zhou
     * @Description: 编辑章节信息回显 根据课程章节id查找对应的课程章节信息
     * @DateTime: 2021/10/12 19:36
     * @Params: * @Param courseSectionId:
     * @Return: * @return: ResponseResultVO
     */
    @RequestMapping("showCourseSection/{courseSectionId}")
    public ResultVO showCourseSection(@PathVariable Integer courseSectionId) {
        CourseSectionVO courseSectionVO = courseContentService.showCourseSection(courseSectionId);
        return ResultVO.ok(Constants.SUCCESS_STATUS, Constants.SUCCESS, courseSectionVO);
    }

    /**
     * @Author: qian.zhou
     * @Description: 编辑课时信息回显  根据课程课时id查找对应的课程课时信息
     * @DateTime: 2021/10/12 19:46
     * @Params: * @Param courseLessonId:
     * @Return: * @return: com.qianzhou.eduCommon.vo.ResultVO
     */
    @RequestMapping("/showCourseLesson/{courseLessonId}")
    public ResultVO showCourseLesson(@PathVariable Integer courseLessonId) {
        CourseLessonVO courseLessonVO = courseContentService.showCourseLesson(courseLessonId);
        return ResultVO.ok(Constants.SUCCESS_STATUS, Constants.SUCCESS, courseLessonVO);
    }
    /**
    * @Author: qian.zhou
    * @Description: 新建&修改章节信息
    * @DateTime: 2021/10/12 20:02
    * @Params: * @Param dto:
    * @Return: * @return: com.qianzhou.eduCommon.vo.ResultVO
    */
    @RequestMapping("/saveOrUpdateSection")
    public ResultVO saveOrUpdateSection(@RequestBody CourseSectionDTO dto) {
        if (dto.getId() != null) {
            courseContentService.updateSection(dto);
            return ResultVO.ok(Constants.SUCCESS_STATUS, Constants.UPDATE_SUCCESS, null);
        } else {
            courseContentService.saveSection(dto);
            return ResultVO.ok(Constants.SUCCESS_STATUS, Constants.INSERT_FAILURE, null);
        }
    }

    /**
    * @Author: qian.zhou
    * @Description: 新建/修改课时信息
    * @DateTime: 2021/10/12 20:02
    * @Params: * @Param dto:
    * @Return: * @return: com.qianzhou.eduCommon.vo.ResultVO
    */
    @RequestMapping("/saveOrUpdateLesson")
    public ResultVO saveOrUpdateLesson(@RequestBody CourseLessonDTO dto) {
        if (dto.getId() != null) {
            courseContentService.updateLesson(dto);
            return ResultVO.ok(Constants.SUCCESS_STATUS, Constants.UPDATE_SUCCESS, null);
        } else {
            courseContentService.saveLesson(dto);
            return ResultVO.ok(Constants.SUCCESS_STATUS, Constants.INSERT_FAILURE, null);
        }
    }

    /**
    * @Author: qian.zhou
    * @Description: 更新课时状态
    * @DateTime: 2021/10/12 20:03
    * @Params: * @Param dto:
    * @Return: * @return: com.qianzhou.eduCommon.vo.ResultVO
    */
    @RequestMapping("/updateLessonStatus")
    public ResultVO updateLessonStatus(@RequestBody CourseLessonDTO dto) {
        courseContentService.updateLessonStatus(dto);
        return ResultVO.ok(Constants.SUCCESS_STATUS, Constants.UPDATE_SUCCESS, null);
    }

    /**
    * @Author: qian.zhou
    * @Description: 上传视频
    * @DateTime: 2021/10/12 20:03
    * @Params:
    * @Return: * @return: com.qianzhou.eduCommon.vo.ResultVO
    */
    @RequestMapping("/uploadVideo")
    public ResultVO uploadVideo() {
        return ResultVO.ok(Constants.SUCCESS_STATUS, Constants.SUCCESS, null);
    }
}
